package com.example.demo.service;

import com.example.demo.dao.UserInfoTestRepository;
import com.example.demo.entity.UserInfoTest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @Author: Pinp
 * @Date: 2021/7/21 1:12
 */

@Service
public class UserInfoTestService {

    @Resource
    private UserInfoTestRepository uiRepo;

    public void addUser(String name, Integer age, String password){
        UserInfoTest ui = new UserInfoTest();
        ui.setName(name);
        ui.setAge(age);
        ui.setPassword(password);
        uiRepo.save(ui);
    }

    public String getUserInfo(int UserId){
        return uiRepo.getById(UserId).toString();
    }

    public List<UserInfoTest> getAllUsers(){
        return uiRepo.findAll();
    }

    public Optional<UserInfoTest> getUser(String name, String password) {
        return uiRepo.findByNameAndPassword(name, password);
    }

    public Optional<List<UserInfoTest>> getUsers(String name, String password){
        return uiRepo.getByNameAndPassword(name, password);
    }
    
}
